import { get, post } from "@/service/request.js"
import { CategoryResponse, getPexelsHintResponse, LoginParams, LoginResponse, PexelsListResponse, PexelsQuery, ProfileResponse, RegisterParams } from "@/types/index.js"

// 获取分类
export const getCategoryApi = (): Promise<CategoryResponse> => {
  return get({}, '/category')
}

// 获取图片列表
export const getPexelsListApi = (data: PexelsQuery): Promise<PexelsListResponse> => {
  return get({}, '/pexels/list', data)
}

// 获取搜索提示
export const getPexelsHintApi = (q: string): Promise<getPexelsHintResponse> => {
  return get({}, "/pexels/hint", { q })
}

export const userLoginApi = (data: LoginParams): Promise<LoginResponse> => {
  return post({}, '/sys/login', data)
}

export const getProfileApi = (): Promise<ProfileResponse> => {
  return get({}, '/user/profile')
}

export const userRegisterApi = (data: RegisterParams) => {
  return post({}, '/sys/register', data)
}

export const CaptchaApi = (behavior: number[]): Promise<boolean> => {
  return post({}, '/sys/captcha', { behavior })
}

// 获取微信登录前置数据
export const getWXLoginData = () => get({}, '/sys/wxlogin/data')

// 获取微信登录accesstoken
export const getWXLoginToken = (appid: string, secret: string, code: string) => {
  return get({}, '/sys/wxlogin/access_token', {
    appid,
    secret,
    code
  })
}

// 获取微信登录用户信息
export const getWXLoginUserInfo = (accessToken: string, openid: string) => {
  return get({}, '/sys/wxlogin/userinfo', {
    accessToken,
    openid
  })
}